package com.sdlight.snowflake.dto;

import cn.hutool.core.util.StrUtil;
import lombok.Data;

/**
 * 统一返回值.
 * <p>这个class根据需要自行定义</p>
 *
 * @author lihaitao
 */
@Data
public class ApiRespBase<T> implements java.io.Serializable {

    private int code;

    private String msg;

    private int resultcode;

    private String resultmsg;

    /**
     * 执行用时.
     */
    private String time;

    /**
     * 返回的数据.
     */
    private T data;

    public static <T> ApiRespBase success(final T data) {
        ApiRespBase m = new ApiRespBase();
        m.setCode(200);
        m.setMsg("success");
        m.setResultcode(1);
        m.setResultmsg("业务成功");
        m.setData(data);
        return m;
    }

    public static ApiRespBase fail(final String resultMsg) {
        ApiRespBase m = new ApiRespBase();
        m.setCode(200);
        m.setMsg("success");
        m.setResultcode(0);
        if (StrUtil.isNotEmpty(resultMsg)) {
            m.setResultmsg(resultMsg);
        } else {
            m.setResultmsg("业务失败");
        }
        return m;
    }

    /**
     * 是否通信成功.
     *
     * @return 是否通信成功
     */
    public boolean getIsCommunicateSuccess() {
        return true;
    }
}
